from cgi import print_arguments
from typing import Any


class Decorator:

    def __init__(self, name) -> None:
        print(name)
        self.name = name

    def __call__(self, func, *args: Any, **kwds: Any) -> Any:
        print('调用了Decorator的__call__')
        print(f"装饰器的名字{self.name}")

        def inner(foo_self, *args):  # 返回的函数参数应于被装饰的函数相同
            print(foo_self.name)
            print("我是装饰后的函数")
            return func(foo_self, *args)

        return inner


descirber = Decorator

class Foo:

    def __init__(self):
        self.name = 'Foo class'

    @descirber('Decorator') 
    def foo(self):
        return 'Foo 实例上的 foo'


f = Foo()  # 当类进行实例化的时候，他就会调用装饰器进行装饰
print(f.foo())


class Class_decorator:
    def __init__(self,cls) -> None:
        self.cls = cls

    def __call__(self, *args: Any, **kwds: Any) -> Any:
        self.cls.name = "Class_decorator_name"
        return self.cls


@Class_decorator
class Animal:
    pass


animal = Animal()
print(animal.name)


class Class_decorator2:
    def __init__(self,name) -> None:
        self.name = name

    def __call__(self, cls) -> Any:
        cls.name = self.name
        return cls

@Class_decorator2("旺财")
class Dog:
    pass

dog = Dog()
print(dog.name)
